home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / checkfs.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2008-10-14  |  4KB  |  138 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          checkfs
  4. # Required-Start:    checkroot
  5. # Required-Stop:
  6. # Should-Start:      mtab cryptdisks
  7. # Default-Start:     S
  8. # Default-Stop:
  9. # Short-Description: Check all filesystems.
  10. ### END INIT INFO
  11.  
  12. # Include /usr/bin in path to find on_ac_power if /usr/ is on the root
  13. # partition.
  14. PATH=/sbin:/bin:/usr/bin
  15. FSCK_LOGFILE=/var/log/fsck/checkfs
  16. [ "$FSCKFIX" ] || FSCKFIX=no
  17. . /lib/init/vars.sh
  18.  
  19. . /lib/lsb/init-functions
  20. . /lib/init/splash-functions-base
  21. . /lib/init/usplash-fsck-functions.sh
  22.  
  23. do_start () {
  24.     # See if we're on AC Power.  If not, we're not gonna run our
  25.     # check.  If on_ac_power (in /usr/) is unavailable, behave as
  26.     # before and check all file systems needing it.
  27.     if which on_ac_power >/dev/null 2>&1
  28.     then
  29.         on_ac_power >/dev/null 2>&1
  30.         if [ $? -eq 1 ]
  31.         then
  32.             [ "$VERBOSE" = no ] || log_success_msg "Running on battery power, so skipping file system check."
  33.             BAT=yes
  34.         fi
  35.     fi
  36.  
  37.     #
  38.     # Check the rest of the file systems.
  39.     #
  40.     if [ ! -f /fastboot ] && [ ! "$BAT" ] && [ "$FSCKTYPES" != "none" ]
  41.     then
  42.         if [ -f /forcefsck ]
  43.         then
  44.             force="-f"
  45.         else
  46.             force=""
  47.         fi
  48.         if [ "$FSCKFIX" = yes ]
  49.         then
  50.             fix="-y"
  51.         else
  52.             fix="-a"
  53.         fi
  54.         spinner="-C"
  55.         case "$TERM" in
  56.           dumb|network|unknown|"")
  57.             spinner=""
  58.             ;;
  59.         esac
  60.         [ "$(uname -m)" = s390 ] && spinner=""  # This should go away
  61.         FSCKTYPES_OPT=""
  62.         [ "$FSCKTYPES" ] && FSCKTYPES_OPT="-t $FSCKTYPES"
  63.         handle_failed_fsck() {
  64.             log_failure_msg "File system check failed. 
  65. A log is being saved in ${FSCK_LOGFILE} if that location is writable. 
  66. Please repair the file system manually."
  67.             log_warning_msg "A maintenance shell will now be started. 
  68. CONTROL-D will terminate this shell and resume system boot."
  69.             # Start a single user shell on the console
  70.             if ! sulogin $CONSOLE
  71.             then
  72.                 log_failure_msg "Attempt to start maintenance shell failed. 
  73. Continuing with system boot in 5 seconds."
  74.                 sleep 5
  75.             fi
  76.         }
  77.         if [ "$VERBOSE" = no ]
  78.         then
  79.             log_action_begin_msg "Checking file systems"
  80.                         if pidof usplash; then
  81.                             PROGRESS_FILE=`mktemp` || exit 1
  82.                             set -m
  83.                             logsave -s $FSCK_LOGFILE fsck -C3 -R -A $fix $force $FSCKTYPES_OPT >/dev/console 2>&1 3>$PROGRESS_FILE &
  84.                             set +m
  85.                             usplash_progress "$PROGRESS_FILE"
  86.                             rm -f $PROGRESS_FILE
  87.                         else
  88.                             logsave -s $FSCK_LOGFILE fsck $spinner -R -A $fix $force $FSCKTYPES_OPT
  89.                             FSCKCODE=$?
  90.                         fi
  91.  
  92.             if [ "$FSCKCODE" -gt 1 ]
  93.             then
  94.                 log_action_end_msg 1 "code $FSCKCODE"
  95.                 handle_failed_fsck
  96.             else
  97.                 log_action_end_msg 0
  98.             fi
  99.         else
  100.             if [ "$FSCKTYPES" ]
  101.             then
  102.                 log_action_msg "Will now check all file systems of types $FSCKTYPES"
  103.             else
  104.                 log_action_msg "Will now check all file systems"
  105.             fi
  106.             logsave -s $FSCK_LOGFILE fsck $spinner -V -R -A $fix $force $FSCKTYPES_OPT
  107.             FSCKCODE=$?
  108.             if [ "$FSCKCODE" -gt 1 ]
  109.             then
  110.                 handle_failed_fsck
  111.             else
  112.                 log_success_msg "Done checking file systems. 
  113. A log is being saved in ${FSCK_LOGFILE} if that location is writable."
  114.             fi
  115.         fi
  116.     fi
  117.     rm -f /fastboot /forcefsck
  118. }
  119.  
  120. case "$1" in
  121.   start|"")
  122.     do_start
  123.     ;;
  124.   restart|reload|force-reload)
  125.     echo "Error: argument '$1' not supported" >&2
  126.     exit 3
  127.     ;;
  128.   stop)
  129.     # No-op
  130.     ;;
  131.   *)
  132.     echo "Usage: checkfs.sh [start|stop]" >&2
  133.     exit 3
  134.     ;;
  135. esac
  136.  
  137. :
  138.